package com.example.mycomposelesson.util

import com.giftedcat.serialportlibrary.SerialPortManager
import com.giftedcat.serialportlibrary.listener.OnOpenSerialPortListener
import mu.KotlinLogging
import java.io.File

object SerialUtil {
    private val logger= KotlinLogging.logger {  }
    var serialPortManager:SerialPortManager?


    init {
        serialPortManager= SerialPortManager(File("/dev/ttyS0"),1200)
        logger.error{"serialPortManager init=${serialPortManager}"}
        //SerialPortManager.openLog()
    }

    fun reInitSerialPort(){
        serialPortManager= SerialPortManager(File("/dev/ttyS0"),1200)
        logger.error{"serialPortManager reInit=${serialPortManager}"}
    }
    fun closeSerialPort(){
        if(serialPortManager!=null){
            serialPortManager!!.closeSerialPort()
            serialPortManager=null
            logger.error{"serialPortManager 串口已关闭"}
        }
    }
}